const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const srcPath=path.join(__dirname, '/src');
module.exports = {
    // devtool: 'inline-source-map',
    entry: path.join(__dirname,"/src/index.js"), //已多次提及的唯一入口文件
    output: {
        path: path.join(__dirname, '/dist'), //打包后的文件存放的地方
        filename: "bundle.js", //打包后输出文件的文件名
    },
    module: {
        rules: [
          {
              test: /\.js|jsx$/,
              exclude: /(node_modules|bower_components)/,
              use: {
                loader: 'babel-loader',
                options: {
                  presets: ['env']
                }
              }
          },
          {
              test: /\.css$/,
              use: [
                  {
                     loader: 'css-loader',
                     options: {
                        modules: true
                     }
                  },
                  {
                     loader:'style-loader' 
                  }
              ]
             
          },
          {
              test: /\.less$/,
              use: [{
                  loader: "style-loader" // creates style nodes from JS strings
              }, {
                  loader: "css-loader" // translates CSS into CommonJS
              }, {
                  loader: "less-loader" // compiles Less to CSS
              }]
          },
          {
              test: /\.(html)$/,
              use: {
                  loader: 'html-loader',
                  options: {
                    attrs: [':data-src']
                  }
              }
          },
          {
            test: /\.(png|svg|jpg|gif)$/,
            use: [
              'file-loader'
            ]
          },
          {
            test: /\.(woff|woff2|eot|ttf|otf)$/,
            use: [
              'file-loader'
            ]
          }
      ]
    },
    resolve: {
        extensions: [".js", ".json", ".jsx", ".css"],
        alias: {
          actions: `${srcPath}/actions/`,
          components: `${srcPath}/components/`,
          sources: `${srcPath}/sources/`,
          stores: `${srcPath}/stores/`,
          styles: `${srcPath}/styles/`
        }
    },
    devtool: 'inline-source-map',
    devServer: {
      contentBase: path.join(__dirname, "dist"),
      compress: true,
      historyApiFallback: true,
      inline: true,
      proxy: {
            "/api/*": {
                target: 'http://localhost:80',
                //pathRewrite: {'^/api' : '/advanced/api/web/v1'},
                changeOrigin: true
            }
        }
    },
    // 在配置中添加插件
    plugins: [
      // 构建优化插件
      new HtmlWebpackPlugin({
        filename:'index.html',
        template:'src/index.html'
      }),
      new webpack.HotModuleReplacementPlugin()

    ]
    
}